package cn.ai.boot.config.PCF;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author jie.zhao@dms365.com
 * @Date 2025/7/18 16:31
 */
public class Testified33 {

    public static void main(String[] args) {
        MainKey mainKey = new MainKey("1", "2", "3");
        Map<MainKey, String> mainTableMap = new HashMap<>();
        mainTableMap.put(mainKey, "value");
        System.out.println(mainKey.hashCode());

        MainKey mainKey2 = new MainKey("1", "2", "3");
        mainTableMap.put(mainKey2, "222");
        System.out.println(mainKey.hashCode());

    }

    private static class MainKey {
        private final String pipelineNumber;
        private final String device;
        private final String unit;

        public MainKey(String pipelineNumber, String device, String unit) {
            this.pipelineNumber = pipelineNumber;
            this.device = device;
            this.unit = unit;
        }

        // 必须重写 equals & hashCode
        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            MainKey mainKey = (MainKey) o;
            return Objects.equals(pipelineNumber, mainKey.pipelineNumber) &&
                    Objects.equals(device, mainKey.device) &&
                    Objects.equals(unit, mainKey.unit);
        }

        @Override
        public int hashCode() {
            return Objects.hash(pipelineNumber, device, unit);
        }
    }
}

